﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ITMAN.AssetMan_FRMs
{
    public partial class FRM_assetman_start : Form
    {
        public FRM_assetman_start()
        {
            InitializeComponent();
        }

        private void FRM_assetman_start_Load(object sender, EventArgs e)
        {
            Klassen.CL_assetman assetman = new Klassen.CL_assetman();
            List<string> kategorien = assetman.get_kategorien();
            for (int i = 0; i < kategorien.Count(); i++)
            {
                CMB_kategorie.Items.Add(kategorien[i]);
            }
            DGV_overview.DataSource = assetman.get_assets_to_datatable();

        }

        private void MENU_bearbeiten_itemAnlegen_Click(object sender, EventArgs e)
        {
            FRM_neues_asset neues_asset = new FRM_neues_asset();
            neues_asset.Show();
        }

        private void CMB_kategorie_SelectedIndexChanged(object sender, EventArgs e)
        {
            Klassen.CL_assetman assetman = new Klassen.CL_assetman();
            DGV_overview.DataSource = assetman.get_assets_to_datatable(CMB_kategorie.Text);
        }

        private void MENU_bearbeiten_item_bearbeiten_Click(object sender, EventArgs e)
        {
            if (DGV_overview.SelectedCells.Count > 0)
            {
                int selectedrowindex = DGV_overview.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow = DGV_overview.Rows[selectedrowindex];
                string asset_nr = Convert.ToString(selectedRow.Cells["asset_nr"].Value);
                AssetMan_FRMs.FRM_asset_bearbeiten.asset_nr = asset_nr;
                AssetMan_FRMs.FRM_asset_bearbeiten FRM = new FRM_asset_bearbeiten();
                FRM.Show();
            }
            else
            {
                MessageBox.Show("Bitte wählen sie 1 Datensatz zur bearbeitung aus");
            }
        }

        private void MENU_bearbeiten_item_löschen_Click(object sender, EventArgs e)
        {
            Klassen.CL_assetman assetman = new Klassen.CL_assetman();
            if (DGV_overview.SelectedCells.Count > 0)
            {
                int selectedrowindex = DGV_overview.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow = DGV_overview.Rows[selectedrowindex];
                string asset_nr = Convert.ToString(selectedRow.Cells["asset_nr"].Value);
                assetman.delete_asset(asset_nr,selectedRow);
            }
        }

        private void DGV_overview_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void BNT_schnell_wartung_Click(object sender, EventArgs e)
        {
            AssetMan_FRMs.FRM_asset_wartung frm_asset_wartung = new FRM_asset_wartung();
            if (DGV_overview.SelectedCells.Count > 0)
            {
                int selectedrowindex = DGV_overview.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow = DGV_overview.Rows[selectedrowindex];
                string asset_nr = Convert.ToString(selectedRow.Cells["asset_nr"].Value);
                AssetMan_FRMs.FRM_asset_wartung.asset_nr = asset_nr;
                frm_asset_wartung.Show();
            }
            else
            {
                MessageBox.Show("Bitte wählen sie 1 Datensatz zur bearbeitung aus");
            }
        }

        private void BTN_suchen_Click(object sender, EventArgs e)
        {
            Klassen.CL_assetman assetman = new Klassen.CL_assetman();
            DGV_overview.DataSource = assetman.search_assets(EDT_suchen.Text);
        }

        private void DGV_overview_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                

            }
        }

        private void mDTDetailsAnlegenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AssetMan_FRMs.FRM_mdt_details frm_mdt_details = new FRM_mdt_details();
            if (DGV_overview.SelectedCells.Count > 0)
            {
                int selectedrowindex = DGV_overview.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow = DGV_overview.Rows[selectedrowindex];
                string asset_nr = Convert.ToString(selectedRow.Cells["asset_nr"].Value);
                AssetMan_FRMs.FRM_mdt_details.asset_nr = asset_nr;
                frm_mdt_details.Show();
            }
            else
            {
                MessageBox.Show("Bitte wählen sie 1 Datensatz zur bearbeitung aus");
            }
            
        }
    }
}
